package com.hns.can.mina.handle;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @版权：HNS 版权所有 (c) 2013
 * @author:Fisher
 * @version Revision 1.0.0
 * @email:zhuangcaijin@126.com
 * @see:
 * @创建日期：2015-10-9
 * @功能说明：
 * @begin
 * @修改记录:
 * @修改后版本          修改人      	修改内容
 * @2015-10-9  	         Fisher        	创建
 * @end
 */
public class SocketUtil {  
    
    /** 
     * 创建ServerSocket 
     * @param port 
     * @return 
     */  
    public static ServerSocket getServerSocket(int port){  
        ServerSocket server = null;  
        try {  
            server = new ServerSocket(port);  
            return server;  
        } catch (IOException e) {  
            throw new RuntimeException("创建ServerSocket时发生异常，Port:"+port,e);  
        }  
    }  
      
    /** 
     * 获取Socket 
     * @param server 
     * @return 
     */  
    public static Socket getSocket(ServerSocket server){  
        Socket socket = null;  
        try {  
            socket = server.accept();  
            //System.out.println("------Socket连接成功，IP:"+socket.getInetAddress());  
            return socket;  
        } catch (IOException e) {  
            throw new RuntimeException("创建Socket时发送异常",e);  
        }  
    }  
      
}